package com.abhinav;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class Main {

	private static final ThreadLocal<SimpleDateFormat> formatter = new ThreadLocal<SimpleDateFormat>() {

		protected SimpleDateFormat initialValue() {
			return new SimpleDateFormat("yyyyMMdd HHmm");
		}
	};

	public String formatIt(Date date) {
		return formatter.get().format(date);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// floating point calculation
		double amount1 = 2.15;
		double amount2 = 1.10;

		// System.out.println("difference between 2.15 and 1.0 using double is: "
		// + (amount1 - amount2));

		// Use BigDecimal for financial calculation
		BigDecimal amount3 = new BigDecimal("2.15");
		BigDecimal amount4 = new BigDecimal("1.10");
		BigDecimal amount5 = new BigDecimal(2.15);
		BigDecimal amount6 = new BigDecimal(1.10);

		// System.out.println("difference between 2.15 and 1.0 using BigDecimal is: "
		// + (amount3.subtract(amount4)));
		// System.out.println("difference between 2.15 and 1.0 using BigDecimal is: "
		// + (amount5.subtract(amount6)));

		/*
		 * while ((amount1 - amount2) != 1.05) { System.out.println(
		 * "We are stuck in infinite loop due to comparing with floating point numbers"
		 * ); }
		 */

		for (int x = 0, y = 0; x > y; x--, y++) {
			System.out.println(x + " " + y + " ");
		}

		int i = 0, j = 0;
		while (i++ < 2) {
			System.out.println("i - " + i);
			do {
				System.out.println("j - " + j);
			} while (j++ < 2);
		}

		List lst = new ArrayList();
		for (int k = 1; k < 5; k++)
			lst.add(k);
		Iterator iter = lst.iterator();
		for (Object e : lst)
			System.out.println(e);
		
		
//		List lst1 = new ArrayList();
//		lst1.add("1");
//		lst1.add("2");
//		lst1.add("1","3");
//		lst1.add("2", "4");
//		System.out.println(lst1);
//		
	}
}
